//
//  HJLejianCell.m
//  project
//
//  Created by jc on 2019/4/30.
//  Copyright © 2019 健健. All rights reserved.
//

#import "HJLejianCell.h"
#import "YFLikeModel.h"
#import "YFJourneyModel.h"

@interface HJLejianCell ()

/**
 背景
 */
@property (nonatomic,strong,nonnull) UIView * bgView;
/**
 头像
 */
@property (nonatomic,strong,nonnull) UIImageView * mianImageView;

/**
 性别
 */
@property (nonatomic,strong,nonnull) UIImageView * sexImageView;

/**
 名字、年龄、职业
 */
@property (nonatomic,strong,nonnull) UILabel * allTitle;

/**
 去聊天
 */
@property (nonatomic,strong,nonnull) UIButton * chatButton;

/**
 同行
 */
@property (nonatomic,strong,nonnull) UIButton * peerButton;

/**
 数据模型
 */
@property (nonatomic,strong) YFLikeRecordModel * model;

@end

@implementation HJLejianCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self ==[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self initSubViews];
    }
    return self;
}


-(void)loadCellDataWithModel:(YFLikeRecordModel *)model {
    self.model = model;
    [self.mianImageView sd_setImageWithURL:[NSURL URLWithString:model.user.avatar] placeholderImage:nil];
    self.sexImageView.image = model.user.sexImage;
    self.allTitle.text = [NSString stringWithFormat:@"%@ %@岁 %@",model.user.nickName,model.user.age,model.user.vocationName.length == 0 ? @"" : model.user.vocationName];
}


// 已成行数据
-(void)loadLineCellDataWithModel:(HJUserListModel *)model {
    [self.mianImageView sd_setImageWithURL:model.user.avatarURL];
    self.sexImageView.image = model.user.sexImage;
    self.allTitle.text = [NSString stringWithFormat:@"%@ %@岁 %@",model.user.nickName,model.user.age,model.user.vocationName.length == 0 ? @"" : model.user.vocationName];
}


-(void)initSubViews {
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.backgroundColor = [UIColor clearColor];
    // 背景
    UIView * bgView = [UIView new];
    [bgView rounded:UIRectCornerAllCorners radius:6];
    bgView.backgroundColor = [UIColor whiteColor];
    self.bgView = bgView;
    [self.contentView addSubview:bgView];
    
    // 头像
    UIImageView * mianImageView = [UIImageView new];
    mianImageView.image = setImage(@"touxiang1");
    [mianImageView rounded:UIRectCornerAllCorners radius:22 borderColor:[UIColor colorWithHex:0x000000] borderWidth:1];
    self.mianImageView = mianImageView;
    [bgView addSubview:mianImageView];
    
    // 性别
    UIImageView * sexImageView = [UIImageView new];
    sexImageView.image = setImage(@"ico_mine_female");
    self.sexImageView = sexImageView;
    [bgView addSubview:sexImageView];
    
    // 名字 年龄 职业
    UILabel * allLabel = [UILabel new];
    allLabel.textColor = [UIColor colorWithHex:0x000000];
    allLabel.font = [UIFont fontWithName:PingFangSC_Medium size:14];
    allLabel.textAlignment = NSTextAlignmentLeft;
    allLabel.text = @"qweqweqweq";
    self.allTitle = allLabel;
    [bgView addSubview:allLabel];
    
    //去聊
    UIButton * chatBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [chatBtn setTitle:@"去聊" forState:0];
    chatBtn.adjustsImageWhenHighlighted = YES;
    chatBtn.titleLabel.font = [UIFont fontWithName:PingFangSC_Medium size:11];
    [chatBtn setTitleColor:[UIColor colorWithHex:0xffffff] forState:0];
    [chatBtn setBackgroundColor:[UIColor blackColor]];
    [self.contentView setupShadowWithView:chatBtn];
    @weakify(self)
    [[chatBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        @strongify(self)
        self.chatBlock(self.model);
    }];
    self.chatButton = chatBtn;
    [bgView addSubview:chatBtn];
    
    // 同行
    UIButton * peerBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [peerBtn setTitle:@"同行" forState:0];
    peerBtn.adjustsImageWhenHighlighted = YES;
    peerBtn.titleLabel.font = [UIFont fontWithName:PingFangSC_Medium size:11];
    [peerBtn setTitleColor:[UIColor colorWithHex:0x000000] forState:0];
    [peerBtn setBackgroundColor:[UIColor whiteColor]];
    [self.contentView setupShadowWithView:peerBtn];
    [[peerBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        @strongify(self)
        self.peerBlock(self.model);
    }];
    self.peerButton = peerBtn;
    [bgView addSubview:peerBtn];
    
}


-(void)layoutSubviews {
    [super layoutSubviews];
    
    @weakify(self)
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        @strongify(self)
        make.top.equalTo(@6);
        make.left.equalTo(self.contentView).with.offset(12);
        make.bottom.equalTo(self.contentView).with.inset(6);
        make.right.equalTo(self.contentView).with.inset(12);
    }];
    
    [self.mianImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        @strongify(self)
        make.left.equalTo(self.bgView).with.offset(14);
        make.centerY.mas_equalTo(self.bgView);
        make.size.mas_equalTo(CGSizeMake(44, 44));
    }];
    
    [self.sexImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        @strongify(self)
        make.top.equalTo(self.mianImageView).with.offset(4);
        make.left.equalTo(self.mianImageView.mas_right).with.offset(5);
        make.size.mas_equalTo(CGSizeMake(self.sexImageView.image.size.width, self.sexImageView.image.size.height));
    }];
    
    [self.chatButton mas_makeConstraints:^(MASConstraintMaker *make) {
        @strongify(self)
        make.top.equalTo(self.bgView).with.offset(10);
        make.right.equalTo(self.bgView).with.inset(12);
        make.size.mas_equalTo(CGSizeMake(55, 24));
    }];
    
    [self.peerButton mas_makeConstraints:^(MASConstraintMaker *make) {
        @strongify(self)
        make.bottom.equalTo(self.bgView).with.inset(10);
        make.right.equalTo(self.bgView).with.inset(12);
        make.size.mas_equalTo(CGSizeMake(55, 24));
    }];
    
    [self.allTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        @strongify(self)
        make.centerY.mas_equalTo(self.sexImageView);
        make.left.equalTo(self.sexImageView.mas_right).with.offset(5);
        make.right.equalTo(self.chatButton.mas_left).with.inset(5);
        make.height.mas_equalTo(30);
    }];
}


@end
